package com.nhjf.admin.servlet;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.nhjf.admin.ueditor.ActionEnter;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @classname: UEditorController
 * @description: 定义 UEditor控制层
 * @author: lixy
 */
@Controller
@Scope("prototype")
@RequestMapping("/uedit")
public class UeditorController {
 
    private static final Logger logger = LoggerFactory.getLogger(UeditorController.class);
//	private String contextPath = null;
//	private  String originalPath;
//	private String actionType = null;
    @RequestMapping(value="/config")
    public void config(HttpServletRequest request, HttpServletResponse response) {
 
        response.setContentType("application/json");
        String rootPath = request.getSession()
                .getServletContext().getRealPath("/");
//        System.out.println("进入UEditorController");
//		this.actionType = request.getParameter( "action" );
//		this.contextPath = request.getContextPath();
//		String url=request.getRequestURI();
//		String test=url.substring( contextPath.length() );
//		if ( contextPath.length() > 0 ) {
//			this.originalPath = rootPath + url.substring( contextPath.length() );
//		} else {
//			this.originalPath = rootPath + url;
//		}
        try {
            String exec = new ActionEnter(request, rootPath).exec();
            PrintWriter writer = response.getWriter();
            writer.write(exec);
            writer.flush();
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
 
    }

}